package com.fury.managers;

import java.util.Properties;

import com.fury.framework.FuryException;
import com.fury.managers.environment.FuryEnvironment;

public class EnvironmentManager implements FuryEnvironment {
	private FuryEnvironment activeEnvironment;
	
	private static EnvironmentManager _instance = new EnvironmentManager();
	
	public static EnvironmentManager getInstance(){
		return _instance;
	}
	
	@Override
	public void startEnvironment(Properties properties) throws FuryException{
		activeEnvironment = null;
		
		String className = properties.getProperty("class");
		
		try {
			activeEnvironment = (FuryEnvironment) Class.forName( className ).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
			throw new FuryException("Could not instanciate [" + className + "]", e);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			throw new FuryException("Illegal access to class [" + className + "]", e);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new FuryException("Class [" + className + "] was not found.", e);
		}
		
		activeEnvironment.startEnvironment(properties);
	}
	
	@Override
	public void stopEnvironment() throws FuryException{
		activeEnvironment.stopEnvironment();
	}
	
	@Override
	public int getWidth(){
		return activeEnvironment.getWidth();
	}
	
	@Override
	public int getHeigth(){
		return activeEnvironment.getHeigth();
	}
	
	@Override
	public boolean isFullScreen(){
		return activeEnvironment.isFullScreen();
	}

	@Override
	public boolean isClosedRequested() {
		return activeEnvironment.isClosedRequested();
	}
}
